﻿using System;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Windows.Forms;
using PowerMonitor.Common;
using PowerMonitor.Properties;

namespace PowerMonitor
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException); // 未处理异常
            
            //SplashScreen // 启动画面
            //Upgrader upgrade = new Upgrader();
            //if (upgrade.CheckVersion() == false)
            //{
            //    if (Directory.Exists(Application.StartupPath + "\\update\\TestMonitor"))
            //    {
            //        Task.Factory.StartNew(() =>
            //        {
            //            Directory.Delete(Application.StartupPath + "\\update\\TestMonitor", true);
            //        });
            //    }
            //    AppMain.MainForm = new PowerMonitor();
            //    Application.Run(AppMain.MainForm);
            //}
            INIFile file = new INIFile(AppMain.StartPath + Properties.Resources.RegisterPath + "Languege.ini");
            file.ClearAllSection();
            string strLanguage = file.IniReadValue("当前语言", "语言信息");
            if (!string.IsNullOrEmpty(strLanguage))
            {
                Thread.CurrentThread.CurrentCulture = new CultureInfo(strLanguage);
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(strLanguage);
                LangChange.SelectLang(strLanguage);
            }
            AppMain.MainForm = new PowerMonitor();
            Application.Run(AppMain.MainForm);
        }
        static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
        {
            //Console.WriteLine("异常出现时间:" + DateTime.Now.ToString("HH:mm:ss:fff"));
            MessageBox.Show(e.Exception.Message + "\n" + Resources.MsgPleaseCheckConfigOK, Resources.msgTitleTip, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }

}
